/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.intec.matsab.persistence;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Sabrina
 */
    @Entity
    @Table(name = "Historial")
    @NamedQueries({@NamedQuery(name = "Historial.findAll", query = "SELECT h FROM Historial h"),
    @NamedQuery(name = "Historial.findByMatricula", query = "SELECT h FROM Historial h WHERE h.historialPK.matricula = :matricula"),
    @NamedQuery(name = "Historial.findByIdAsignatura", query = "SELECT h FROM Historial h WHERE h.historialPK.idAsignatura = :idAsignatura"),
    @NamedQuery(name = "Historial.findByIdTrimestre", query = "SELECT h FROM Historial h WHERE h.historialPK.idTrimestre = :idTrimestre"),
    @NamedQuery(name = "Historial.findByNumero", query = "SELECT h FROM Historial h WHERE h.historialPK.numero = :numero"),
    @NamedQuery(name = "Historial.findByCalificacion", query = "SELECT h FROM Historial h WHERE h.calificacion = :calificacion"),
    @NamedQuery(name = "Historial.findEstudentsOfSeccion", query = "SELECT h FROM Historial h WHERE h.historialPK.idTrimestre = :idTrimestre AND h.historialPK.idAsignatura = :idAsignatura")})
public class Historial implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected HistorialPK historialPK;
    @Column(name = "calificacion")
    private Integer calificacion;
    @JoinColumn(name = "matricula", referencedColumnName = "matricula", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Estudiante estudiante;
    @JoinColumns({@JoinColumn(name = "numero", referencedColumnName = "numero", insertable = false, updatable = false), @JoinColumn(name = "idTrimestre", referencedColumnName = "idTrimestre", insertable = false, updatable = false), @JoinColumn(name = "idAsignatura", referencedColumnName = "idAsignatura", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Seccion seccion;
    @JoinColumn(name = "idEstado", referencedColumnName = "idEstado")
    @ManyToOne(optional = false)
    private Estado idEstado;

    public Historial() {
    }

    public Historial(HistorialPK historialPK) {
        this.historialPK = historialPK;
    }


    public Historial(int matricula, String idAsignatura, int idTrimestre, int numero) {
        this.historialPK = new HistorialPK(matricula, idAsignatura, idTrimestre, numero);
    }

    public HistorialPK getHistorialPK() {
        return historialPK;
    }

    public void setHistorialPK(HistorialPK historialPK) {
        this.historialPK = historialPK;
    }

    public Integer getCalificacion() {
        return calificacion;
    }

    public void setCalificacion(Integer calificacion) {
        this.calificacion = calificacion;
    }

    public Estudiante getEstudiante() {
        return estudiante;
    }

    public void setEstudiante(Estudiante estudiante) {
        this.estudiante = estudiante;
    }

    public Seccion getSeccion() {
        return seccion;
    }

    public void setSeccion(Seccion seccion) {
        this.seccion = seccion;
    }

    public Estado getIdEstado() {
        return idEstado;
    }

    public void setIdEstado(Estado idEstado) {
        this.idEstado = idEstado;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (historialPK != null ? historialPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Historial)) {
            return false;
        }
        Historial other = (Historial) object;
        if ((this.historialPK == null && other.historialPK != null) || (this.historialPK != null && !this.historialPK.equals(other.historialPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.intec.matsab.persistence.Historial[historialPK=" + historialPK + "]";
    }
}
